﻿<cfsilent>
	<cfscript>
	
		termID = event.getArg("TID");
		courseID = event.getArg("CID");
		
		sql = "SELECT course_name FROM t_course WHERE cid = :courseId " ;
				
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="courseId", value=courseID, cfsqltype="cf_sql_varchar" );
		rs_courseEntity = queryObj.execute( sql=sql ).getResult();
		
		
		sql = "SELECT sbj_id, sbj_short  FROM t_subject WHERE sbj_id = :subjectId " ;
				
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="subjectId", value=event.getArg('SubID'), cfsqltype="cf_sql_varchar" );
		rs_subjectEntity = queryObj.execute( sql=sql ).getResult();

		event.setArg("pageTitle", "教学运行基础数据 - 教学计划 - 计划课程授课班级");
		
		rs_class = queryNew("p_id");

		if ( len(termID) and len(courseID) ) {
			
			sql = "SELECT 
						t_plan.p_id, 
						t_class.cls_name, 
						t_class.grade, 
						t_plan.cidx, 
						t_campus.campus_name, 
						t_class.cls_size,
						t_class.cls_scale, 
						t_subject.sbj_short, 
						t_course_nature.cna_name, 
						t_course_prop.prop_name 
					FROM 
						t_plan 
						INNER JOIN t_class ON t_class.cls_id = t_plan.cls_id 
						INNER JOIN t_campus ON t_campus.campus_id = t_class.campus_id 
						INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
						INNER JOIN t_course_nature ON t_course_nature.cna_id = t_plan.cna_id 
						INNER JOIN t_course_prop ON t_course_prop.prop_id = t_plan.prop_id 
					WHERE 
						t_plan.term_id = :termId 
						AND 
						t_plan.cid = :courseId 
					ORDER BY 
						t_class.cls_id " ;
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="termId", value=termID, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value=courseID, cfsqltype="cf_sql_varchar" );
			rs_class = queryObj.execute( sql=sql ).getResult();
		}
	
		passArgs = structNew();
		structInsert(passArgs, "SubID", rs_subjectEntity.sbj_id, true);
	
		if ( rs_class.recordCount ) {
			structInsert(passArgs, "Grade", rs_class["grade"][1], true);
		}
	
	</cfscript>	
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('planSchemaBySubject', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText"><cfoutput>#rs_subjectEntity.sbj_short#</cfoutput>专业学期开课计划</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 info"></i><cfoutput>#rs_courseEntity.course_name#</cfoutput>
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="tabContentBox">
					<cfif rs_class.recordCount>
						<cfset row = 0 />
						<table class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="50">校区</td>
									<td width="30">年级</td>
									<td width="60">专业</td>
									<td width="60">行政班</td>
									<td width="80">是否执行</td>
									<td>类别</td>
									<td width="48">课程性质</td>
									<td width="48">计划人数</td>
									<td width="48">实际人数</td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_class">
									<cfset row++ />
									<tr class="editRows" rowid="<cfoutput>#rs_class.p_id#</cfoutput>">
										<td class="index"><cfoutput>#row#</cfoutput></td>
										<td><cfoutput>#rs_class.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_class.grade#</cfoutput></span></td>
										<td><cfoutput>#rs_class.sbj_short#</cfoutput></td>
										<td><cfoutput>#rs_class.cls_name#</cfoutput></td>
										<td><a rowid="<cfoutput>#rs_class.p_id#</cfoutput>" usage="ForCourse" class="stat <cfif rs_class.cidx eq "XXX">no<cfelse>yes</cfif>"></a></td>
										<td><cfoutput>#rs_class.cna_name#</cfoutput></td>
										<td><cfoutput>#rs_class.prop_name#</cfoutput></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_class.cls_size#</cfoutput></span></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_class.cls_scale#</cfoutput></span></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</cfif>
					
					<script language="javascript" type="text/javascript">
						//<![CDATA[
						<!--
						$(document).ready(function() {
							
							/* isCourseArrange trigger */
							$("a[usage]").click(function(){
								
								var rowid = $(this).attr("rowid");
								var method = $(this).attr("usage");
							
								var status = $(this).hasClass("yes");
								var newStatus = true;
								
								/* 切换状态数据 */
								if (status) {
									newStatus = false;
								}
								
								/* 发送请求 */
								$(this).removeClass("no").removeClass("yes").addClass("waiting");
								
								$.post(
										"<cfoutput>#buildURL('apiPlanSchemaClassPropChange')#</cfoutput>", 
										{
											'pid' : rowid,
											'prop' : method,
											'status' : newStatus,
											'seed': (new Date()).getTime()
										}, 
										function(data) {

											var result = jQuery.parseJSON(data);
											
											var $trigger = $("a[usage][rowid='" + result.PlanID + "']")
											
											$trigger.removeClass("waiting");
											
											/* 刷新是否排课状态数据 */
											if (result.CourseIndex == "XXX") {
												$trigger.addClass("no");
											}
											else {
												$trigger.addClass("yes");
											}
											
											
										});
								
								
							});
							
						});
						// -->
						//]]>
					</script>
					
				</div>
			</div>
		</li>
	</ul>
</div>

